#ifndef __SERIAL_H
#define __SERIAL_H
#include "device.h"
#include "usart.h"

#define CMD_REV_INIT            (1)
#define CMD_GET_REV_POINT       (2)
#define CMD_SET_RS485           (3)

#define RS485_MODE_REV      (0)
#define RS485_MODE_SEND     (1)

typedef struct
{
    uint32_t baud_rate;
    uint8_t data_bits;
    uint8_t stop_bits;
    uint8_t parity;

    uint16_t revbuf_size;
} serial_configure, *serial_configure_t;

typedef struct
{
    int             (* init) (void *cfg);

    int             (* ioctl) (int cmd, void *arg);
    unsigned int    (* read) (unsigned int pos, void *buffer, unsigned int size, void *opt);
    unsigned int    (* write) (unsigned int pos, void *buffer, unsigned int size, void *opt);
    int             (* readable) (void);
    int             (* writeable) (void);
    void            (* flush) (void);

    int             (* getbyte) (void);
} SERIAL,*SERIAL_t;

#define SERIAL_DEFAULT_CONFIG              \
{                                          \
    BAUD_RATE_115200, /* 115200 bits/s */  \
    DATA_BITS_8,      /* 8 databits */     \
    STOP_BITS_1,      /* 1 stopbit */      \
    PARITY_NONE,      /* No parity  */     \
    256,              /* rev buffer size */  \
}

typedef  void (*rs485_mode)(uint8_t mode);


#endif
